package com.videoaggre.zcl.helper.player.cover

import android.content.Context
import android.os.Bundle
import android.view.View
import com.kk.taurus.playerbase.entity.DataSource
import com.kk.taurus.playerbase.receiver.BaseCover
import com.kk.taurus.playerbase.receiver.IReceiverGroup
import com.videoaggre.zcl.R
import com.videoaggre.zcl.common.bindViewClick
import com.videoaggre.zcl.common.changeVisibility
import com.videoaggre.zcl.helper.player.DataInter
import com.videoaggre.zcl.utils.GlideUtils
import com.videoaggre.zcl.utils.Logger

class ImageCover(context: Context?) : BaseCover(context) {
    private var isStart = false
    override fun onReceiverBind() {
        super.onReceiverBind()
        groupValue.registerOnGroupValueUpdateListener(mOnGroupValueUpdateListener)
//        bindViewClick(::onViewClick, mBackIcon, mStateIcon, mSwitchScreen, mSeekBarMask)
    }

    private val mOnGroupValueUpdateListener: IReceiverGroup.OnGroupValueUpdateListener = object : IReceiverGroup.OnGroupValueUpdateListener {
        override fun filterKeys(): Array<String> {
            return arrayOf(
                DataInter.Key.KEY_COVER_SHOW,
            )
        }

        override fun onValueUpdate(key: String, value: Any) {
            if (key == DataInter.Key.KEY_COVER_SHOW) {
                GlideUtils.intoView(view.context, value, view.findViewById(R.id.albumImage))
            }
        }
    }

    override fun onPlayerEvent(eventCode: Int, bundle: Bundle?) {
        if (!isStart) {
            setCoverVisibility(View.GONE)
            isStart = true
        }
    }

    override fun onErrorEvent(eventCode: Int, bundle: Bundle?) {

    }

    override fun onReceiverEvent(eventCode: Int, bundle: Bundle?) {

    }

    override fun onCreateCoverView(context: Context?): View {
        return View.inflate(context, R.layout.view_image_cover, null)
    }

    override fun getCoverLevel(): Int {
        return levelMedium(10)
    }
}